package com.jcl.cloud.services.unicrawler.client;

import com.jcl.cloud.services.gateway.common.task.BuyResumeReq;
import com.jcl.cloud.services.gateway.common.task.BuyResumeRsp;
import com.jcl.cloud.services.unicrawler.common.dto.CrawlTaskMgrReq;
import com.jcl.cloud.services.unicrawler.common.dto.GrabRequest;
import com.jcl.cloud.services.unicrawler.common.dto.GrabResult;
import com.jcl.cloud.services.unicrawler.common.dto.UniCrawlTaskRsp;
import org.springframework.web.client.RestTemplate;


public class CrawlerManagerClient {

    private RestTemplate restTemplate;

    public CrawlerManagerClient(RestTemplate restTemplate){
        this.restTemplate = restTemplate;
    }


    public UniCrawlTaskRsp createTask(CrawlTaskMgrReq crawlTaskMgrReq) {
        String url = "http://union-crawler-server/union-crawler/api/v1/manager/tasks";
        UniCrawlTaskRsp uniCrawlTaskRsp = this.restTemplate.postForObject(url,crawlTaskMgrReq,UniCrawlTaskRsp.class);
        return  uniCrawlTaskRsp;
    }


    public GrabResult grabTask(GrabRequest grabRequest){
        String url = "http://union-crawler-server/union-crawler/api/v1/tasks/grab";
        GrabResult grabResult = this.restTemplate.postForObject(url,grabRequest,GrabResult.class);
        return grabResult;
    }


    public BuyResumeRsp buyResume(BuyResumeReq buyResumeReq){
        String url = "http://union-crawler-server/union-crawler/api/v1/tasks/buy/resume";
        BuyResumeRsp buyResumeRsp = this.restTemplate.postForObject(url,buyResumeReq,BuyResumeRsp.class);
        return buyResumeRsp;
    }

}
